package com.code.soulnetty.modbus.client.message;

import com.code.soulnetty.modbus.biz.msg.Message;
import com.google.common.collect.ImmutableSortedSet;
import lombok.Getter;
import org.apache.commons.lang3.tuple.Pair;

/**
 * @author lyf
 * @date 2022-12-17 14:08
 */
@Getter
public class ProtocolRequestWrap implements ProtocolRequest {

    public final static int NON_PERIOD = -1;

    /**
     * period 为 -1 代表非周期性请求
     */
    private int period;

    private long timestamp;

    private ProtocolRequest request;

    private int retryCount;

    public ProtocolRequestWrap(long timestamp, int period, ProtocolRequest request) {
        this.period = period;
        this.request = request;
        this.timestamp = timestamp;
    }

    @Override
    public Pair<Boolean, String> msgIdInfo() {
        return request.msgIdInfo();
    }

    @Override
    public byte[] requestByteData() {
        return request.requestByteData();
    }

    @Override
    public ImmutableSortedSet<Message> requestData() {
        return request.requestData();
    }

    public int getRetryCount() {
        return retryCount;
    }

    public void setRetryCount(int retryCount) {
        this.retryCount = retryCount;
    }
}
